/*
 * Copyright 2021-2030 itbox.com All right reserved. This software is the confidential and proprietary information
 * of itbox.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it
 * only in accordance with the terms of the license agreement you entered into with itbox.com.
 */
package cn.itbox.example.test.controller;

import cn.itbox.example.model.request.CreateUserRequest;
import cn.itbox.example.model.request.UpdateUserRequest;
import cn.itbox.example.model.response.UserResponse;
import cn.itbox.example.service.UserServiceClient;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @BelongProject hxz-aa
 * @BelongPackage cn.itbox.hyb.hxz.aa.controller
 * @Description TODO
 * @ClassName UserFeignController
 * @Author xingc
 * @Date 2023/11/26 17:09
 * @Version 1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/user_feign")
public class UserFeignController {
    @Autowired
    private UserServiceClient userServiceClient;

    @GetMapping
    public List<UserResponse> list() {
        List<UserResponse> roleDOS = userServiceClient.list();
        return roleDOS;
    }

    @PostMapping()
    public UserResponse create(@RequestBody @Valid CreateUserRequest cmd) {
        Long id = userServiceClient.create(cmd);
        UserResponse rolePageDTO = userServiceClient.byId(id);
        return rolePageDTO;
    }

    @PutMapping
    public UserResponse update(@RequestBody @Valid UpdateUserRequest cmd) {
        userServiceClient.update(cmd);
        UserResponse rolePageDTO = userServiceClient.byId(cmd.getId());
        return rolePageDTO;
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable Long id) {
        userServiceClient.delete(id);
    }
}
